#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;


 // Definition for singly-linked list.
  struct ListNode {
      int val;
      ListNode *next;
      ListNode(int x) : val(x), next(NULL) {}
  };

class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        if(head==NULL){
            return NULL;
        }
        if(head->val==val){
            return head->next;
        }
        ListNode* curr = head;
        while(curr!=NULL){
            if(curr->next!=NULL&&curr->next->val==val){
                curr->next = curr->next->next;
                break;
            }
            curr = curr->next;
        }
        return head;
    }
};